package com.zyj.test.month1.day17;

/**
 * @author Yijia Zhang
 * @create 2024-06-06 23:46
 */
public class code2938 {
    //模拟：超时
    public long minimumSteps(String s) {
        int len = s.length();
        if (len <= 1) {
            return 0;
        }
        char[] cs = s.toCharArray();
        int r = len - 1;
        int res = 0;
        while (r > 0) {
            if (cs[r] == '0') {
                int l = r - 1;
                while (l >= 0 && cs[l] == '0') {
                    l--;
                }
                if (l >= 0) {
                    char tmp = cs[l];
                    cs[l] = cs[r];
                    cs[r] = tmp;
                    res += (r - l);
                }
            }
            r--;
        }
        return res;
    }
}
